package com.calculator.oop;

import java.util.Scanner;

public class SimpleCalculator extends Calculator {
    Scanner in = new Scanner(System.in);
    private double num1;
    private double num2;

    public SimpleCalculator(double num1, double num2) {
        setNum1(num1);
        setNum2(num2);
    }

    public double getNum1() {
        return num1;
    }

    public void setNum1(double num1) {
        this.num1 = num1;
    }

    public double getNum2() {
        return num2;
    }

    public void setNum2(double num2) {
        this.num2 = num2;
    }

    @Override
    public void sum() {
        System.out.println(this.getNum1() + this.getNum2());

    }

    @Override
    public void subtract() {
        System.out.println(this.getNum1() - this.getNum2());
    }

    @Override
    public void ride() {
        System.out.println(this.getNum1() * this.getNum2());
    }

    @Override
    public void divide() {
        while (true) {
            if (getNum2() != 0) {
                System.out.println(this.getNum1() / this.getNum2());
                break;
            } else {
                System.out.println("除数不能为0请再次输入");
            }
            setNum2(in.nextDouble());
        }

    }

    public void play(String symbol) {
        System.out.println("请输入第一个数");
        setNum1(in.nextDouble());
        System.out.println("请输入第二个数");
        setNum2(in.nextDouble());
        switch (symbol) {
            case "+":
                this.sum();
            case "-":
                this.subtract();
            case "*":
                this.ride();
            case "/":
                this.divide();
        }
    }
}